package cn.itsource.controller;

import cn.itsource.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/getuser/{id}")
    @HystrixCommand(fallbackMethod="fallback")
    public User getUser(@PathVariable("id") Long id){
        User user = restTemplate.getForObject("http://SERVICE-USER/getuser/"+id,User.class);
        System.out.println(user);
        System.out.println(user);
        return user;
    }

    public User fallback(@PathVariable("id") Long id){
        return new User(-1L,"失败","服务不在了");
    }
}
